<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>项目结题申请（老师）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
</head>
<style>
    .mbox {
        padding: 8px
    }

    .item img {
        height: 40px;
    }

    .btn {
        height: 37px;
    }

    .btn button {
        float: right;
    }
    .openFile input[type=file] {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 18px;
        z-index: 99;
        opacity: 0;
    }

    .typeIpt {
        line-height: 30px;
        margin-left: 10px;
    }
    .layui-icon-ok{
        margin-top: 6px;
    }
</style>
<body>
<div class="mbox">
    <div class="item">
        <img src="../img/yeji.png" alt="" style="margin: 0 5px 0 20px;">
        <span style="font-size: 22px;display: inline-block;vertical-align: middle;">项目结题申请（老师）</span>
    </div>
    <hr class="layui-bg-blue">
    <div class="btn" style="display: inline-flex;">
        <span class="typeIpt layui-form">
            <input type="radio" checked class="approve" lay-filter="status" value="0" name="status" title="未提交"/>&nbsp;
            <input type="radio" lay-filter="status" value="1" name="status" title="待批"/>&nbsp;
            <input type="radio" lay-filter="status" value="2" name="status" title="通过"/>&nbsp;
            <input type="radio" lay-filter="status" value="4" name="status" title="退回"/>&nbsp;
            <input type="radio" lay-filter="status" value="3" name="status" title="不通过"/>&nbsp;
        </span>
    </div>
    <div class="btn">
        <button type="button" class="layui-btn layui-btn-sm" style="background: #2b7fe0">
            <i class="layui-icon layui-icon-upload-drag" style="background: #2b7fe0"></i>导出Excel
        </button>
        <button id="subBtn" type="button" class="layui-btn layui-btn-sm" style="background: #2b7fe0;margin-right: 20px">
            <i class="layui-icon layui-icon-addition" style="vertical-align: inherit"></i>批量提交
        </button>
    </div>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
</body>
</html>
<script type="text/html" id="barDemo">
    <a id="up" class="layui-btn layui-btn-xs" lay-event="up">上传结题资料</a>
    <a id="sub" class="layui-btn layui-btn-xs" lay-event="sub">提交</a>
</script>
<script>
    var ue;   //编辑器的返回值
    var table,form,laydate,upload,laydate;
    //关闭弹框刷新页面
    function closes(){
        layer.closeAll();
        table.reload('test');
    }
    layui.use(['table', 'form', 'layer', 'laydate', 'upload',], function () {
           table = layui.table,
            form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            upload = layui.upload;

        form.render();

        // 初始化结题申请数据
        $.ajax({
            url: '/conclusion_apply/initializationConclusionData'
            , type: 'post'
            , data: {
                trType: "34"
                , trStatus: "2"
                , type: "17"
                , status: "0"
                , flag: false
            }
            , dataType: 'json'
            , async: false
            , success: function (res) {}
        });

        // 查询初始化数据
        var tableData = table.render({
            elem: '#test'
            , url: '/conclusion_apply/getConclusionApply'
            , where: {
                trType: "17"
                , trStatus: "0"
            }
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , defaultToolbar: ['']
            , title: '用户数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'topicName', title: '项目名称'}
                , {field: 'planName', title: '申报计划名称'}
                , {field: 'names', title: '项目成员'}
                , {field: 'headUserName', title: '负责人'}
                , {field: 'type', title: '操作', toolbar: '#barDemo'}
            ]]
            , page: true
        });

        // 批准类型数据查询
        form.on('radio(status)', function (data) {
            switch (data.value) {
                case "0":
                    $("#subBtn").css("display", "block");
                    tableData.reload({
                        where: {
                            trType: "17"
                            , trStatus: data.value
                        }
                    });
                    break;
                case "1":
                    $("#subBtn").css("display", "none");
                    getTableData(29, data.value)
                    break;
                case "2":
                    $("#subBtn").css("display", "none");
                    getTableData(29, data.value)
                    break;
                case "4":
                    $("#subBtn").css("display", "block");
                    tableData.reload({
                        where: {
                            trType: "17"
                            , trStatus: data.value
                        }
                    });
                    break;
                case "3":
                    $("#subBtn").css("display", "none");
                    getTableData(17, data.value)
                    break;
            }
        });

        // 无工具栏表格
        function getTableData(trType, trStatus) {
            table.render({
                elem: '#test'
                , url: '/conclusion_apply/getConclusionApply'
                , where: {
                    trType: trType
                    , trStatus: trStatus
                }
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , defaultToolbar: ['']
                , title: '用户数据表'
                , cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'topicName', title: '项目名称'}
                    , {field: 'planName', title: '申报计划名称'}
                    , {field: 'names', title: '项目成员'}
                    , {field: 'headUserName', title: '负责人'}
                ]]
                , page: true
            });
        }

        // 监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'up') {   // 上传资料
                layer.open({
                    type: 2,
                    title:'上传结题资料',
                    btn: ['保存', '返回'],
                    area: ['50%', '85%'],
                    content:'/rpmPlan/closingView?trId='+data.trId+'&type=0&trType='+data.trType,
                    yes:function (index, layero) {
                        var myIframe = window[layero.find('iframe')[0]['name']];
                        var fnc = myIframe.listSubmit();
                        $("#subBtn").css("display", "block");
                        tableData.reload({
                            where: {
                                trType: "17"
                                , trStatus: 0
                            }
                        });
                    },
                });
            } else if (obj.event === 'sub') {   // 提交
                var newTrType = 29;
                var newTrStatus = 1;
                var oldTrType = data.trType;
                var oldTrStatus = data.trStatus;
                var oldStatusChange = 2
                submitData(data.trId, oldTrType, oldTrStatus, newTrType, newTrStatus, oldStatusChange);
            }
        });

        // 批量提交按钮点击事件
        $('#subBtn').click(function () {
            // 获取表格选中数据
            var checkData = layui.table.checkStatus('test').data;
            if (checkData.length > 0) {
                var trIds = "";
                for (var i = 0; i < checkData.length; i++) {
                    trIds += checkData[i].trId + ",";
                }
                var newTrType = 29;
                var newTrStatus = 1;
                var oldTrType = 17;
                var oldTrStatus = 0;
                var oldStatusChange = 2
                submitData(trIds, oldTrType, oldTrStatus, newTrType, newTrStatus, oldStatusChange);
            } else {
                layer.msg("请选择需要提交的数据", {time: 1500, icon: 7});
            }
        });

        // 提交数据方法
        function submitData(trIds, oldTrType, oldTrStatus, newTrType, newTrStatus, oldStatusChange) {
            $.ajax({
                url: '/conclusion_apply/submitData'
                , type: 'post'
                , data: {
                    ids: trIds
                    , newTrType: newTrType
                    , newTrStatus: newTrStatus
                    , oldTrType: oldTrType
                    , oldTrStatus: oldTrStatus
                    , oldStatusChange: oldStatusChange
                }
                , dataType: 'json'
                , async: false
                , success: function (res) {
                    var msg = "";
                    if (res.code == 0) {
                        layer.msg("提交成功", {time: 1500, icon: 1});
                    } else {
                        layer.msg("提交失败", {time: 1500, icon: 2});
                    }
                    tableData.reload({
                        where: {
                            trType: "17"
                            , trStatus: oldTrStatus
                        }
                    });
                }
            });
        }
    });
</script>
